public class MyQueue implements IQueue{

    static class ListNode {
        public int val;
        public ListNode next;
        public ListNode prev;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;
    public ListNode last;

    public int useSize;

    //入队
    @Override
    public boolean offer(int val) {
        ListNode node=new ListNode(val);
        if (head==null) {
            head=node;
            last=node;
        }else {
            last.next=node;
            node.prev=last;
            last=node;
        }
        useSize++;
        return true;
    }

    //出队
    @Override
    public int poll() {
        if (head == null) {
            return -1;
        }
       if(head.next==null) {
           int retVal=head.val;
           head=null;
           last=null;
           return retVal;
       }
       int retVal=head.val;
       head=head.next;
       head.prev=null;
       return retVal;
    }

    @Override
    public int peek() {
        if (head==null) {
            return -1;
        }
        return head.val;
    }

    @Override
    public int size() {
        return useSize;
    }

    @Override
    public boolean isEmpty() {
        return head==null;
    }
}
